﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <link type="text/css" rel="stylesheet" media="all" href="../styles/global.css"/>
    <link type="text/css" rel="stylesheet" media="all" href="../styles/global_color.css"/>
</head>
<body>
<!--Logo区域开始-->
<div id="header">
    <img src="../images/logo.png" alt="logo" class="left"/>
    <a href="#/logout">[退出]</a>
</div>
<!--Logo区域结束-->
<!--导航区域开始-->
<div id="navi">
    <ul id="menu">
        <li><a href="/index" class="index_on"></a></li>
        <li><a href="/rolelist" class="role_off"></a></li>
        <li><a href="/adminList" class="admin_off"></a></li>
        <li><a href="/feelist" class="fee_off"></a></li>
        <li><a href="/accountlist" class="account_off"></a></li>
        <li><a href="/servicelist" class="service_off"></a></li>
        <li><a href="/billList" class="bill_off"></a></li>
        <li><a href="/reportList" class="report_off"></a></li>
        <li><a href="/userInfo" class="information_off"></a></li>
        <li><a href="/userModiPwd" class="password_off"></a></li>
    </ul>
</div>
<!--导航区域结束-->
<!--主要区域开始-->
<div id="main">
    <!--保存操作的提示信息-->
    <div id="save_result_info" class="save_fail">保存失败！192.168.0.23服务器上已经开通过 OS 账号 “mary”。</div>
    <form action="" method="" class="main_form">
        <!--内容项-->
        <div class="text_info clearfix"><span>身份证：</span></div>
        <div class="input_info">
            <input type="text" id="idcardNo" class="width180"/>
            <input type="button" value="查询账务账号" class="btn_search_large"/>
            <span class="required">*</span>
            <div class="validate_msg_short">没有此身份证号，请重新录入。</div>
        </div>
        <div class="text_info clearfix"><span>账务账号：</span></div>
        <div class="input_info">
            <input type="text" id="loginName" onkeyup="searchAccounts(this);"/>
            <span class="required">*</span>
            <div class="validate_msg_long">没有此账务账号，请重新录入。</div>
        </div>
        <div class="text_info clearfix"><span>资费类型：</span></div>
        <div class="input_info">
            <select id="select">
            </select>
        </div>
        <div class="text_info clearfix"><span>服务器 IP：</span></div>
        <div class="input_info">
            <input type="text" id="unixHost"/>
            <span class="required">*</span>
            <div class="validate_msg_long">15 长度，符合IP的地址规范</div>
        </div>
        <div class="text_info clearfix"><span>登录 OS 账号：</span></div>
        <div class="input_info">
            <input type="text" id="osUsername"/>
            <span class="required">*</span>
            <div class="validate_msg_long">8长度以内的字母、数字和下划线的组合</div>
        </div>
        <div class="text_info clearfix"><span>密码：</span></div>
        <div class="input_info">
            <input type="password" id="loginPasswd"/>
            <span class="required">*</span>
            <div class="validate_msg_long">30长度以内的字母、数字和下划线的组合</div>
        </div>
        <div class="text_info clearfix"><span>重复密码：</span></div>
        <div class="input_info">
            <input type="password" id="loginPasswd2"/>
            <span class="required">*</span>
            <div class="validate_msg_long">两次密码必须相同</div>
        </div>
        <!--操作按钮-->
        <div class="button_info clearfix">
            <input type="button" value="保存" class="btn_save" onclick="showResult();"/>
            <input type="button" value="取消" class="btn_save" onclick="cancel()"/>
        </div>
    </form>
</div>
<!--主要区域结束-->
<div id="footer">
    <span>[源自北美的技术，最优秀的师资，最真实的企业环境，最适用的实战项目]</span>
    <br/>
    <span>版权所有(C)云科技有限公司 </span>
</div>
<script src="../../js/jquery-3.2.1.js"></script>
<script>
    $.ajax({
        url: "/listservice",
        type: "post",
        success: function (data) {
            for (var i in data) {
                var service=data[i];
                var unixHost=service.unixHost;
                var osUsername=service.osUsername;
                for (var j in service.cList){
                    var cList=service.cList[j];
                    var name=cList.name;
                    $("#select").append("<option>"+name+"</option>");
                }
                for (var k in service.aList){
                    var aList=service.aList[k];
                    var idcardNo=aList.idcardNo;
                    var loginName=aList.loginName;
                }
            }
            //$("#idcardNo").val(''+idcardNo+'');
            //$("#loginName").val(''+loginName+'');
            //$("#unixHost").val(''+unixHost+'');
            //$("#osUsername").val(''+osUsername+'');
        }
    });
    function cancel() {
        if (confirm("修改尚未保存，是否取消")) {
            window.location.href = "/servicelist";
        }
    }
    /*function idcardNologinNameisexist(idcardNo,loginName) {
        var isexist=true;
        $.ajax({
            url: "/idcardNologinNameisexist",
            type: "post",
            data:{
                idcardNo:idcardNo,
                loginName:loginName
            },
            success: function (data) {
                isexist= data;
            }
        });
        return isexist;
    }
    function osUsernameisexist(osUsername) {
        if (osUsername==true||osUsername==false){
            return osUsername;
        }else{
            $.ajax({
                url: "/osUsernameisexist",
                type: "post",
                data:{
                    osUsername:osUsername
                },
                success: function (data) {
                    osUsernameisexist(data);
                }
            });
        }

    }*/
    //保存成功的提示信息
    function showResult() {
        var idcardNo=$("#idcardNo").val();
        var loginName=$("#loginName").val();
        $.ajax({
            url: "/idcardNologinNameisexist",
            type: "post",
            data:{
                idcardNo:idcardNo,
                loginName:loginName
            },
            success: function (data) {
                if (data){
                    var accountId=null;
                    $.ajax({
                        url: "/accountIdByidcardNologinName",
                        type: "post",
                        data:{
                            idcardNo:idcardNo,
                            loginName:loginName
                        },
                        success: function (data) {
                            accountId=data;
                            var loginPasswd=$("#loginPasswd").val();
                            var loginPasswd2=$("#loginPasswd2").val();
                            if(loginPasswd==loginPasswd2){
                                var name=$("#select option:selected").text();
                                var costId=null;
                                $.ajax({
                                    url: "/selectCostIdByName",
                                    type: "post",
                                    data:{
                                        name:name
                                    },
                                    success: function (data) {
                                        for (var i in data){
                                            var list=data[i];
                                            costId=list.costId;
                                        }
                                        alert(costId);
                                        var osUsername=$("#osUsername").val();
                                        var unixHost=$("#unixHost").val();
                                        $.ajax({
                                            url: "/osUsernameisexist",
                                            type: "post",
                                            data:{
                                                osUsername:osUsername
                                            },
                                            success: function (data) {
                                                if(data){
                                                    $.ajax({
                                                        url: "/addservice",
                                                        type: "post",
                                                        data:{
                                                            accountId:accountId,
                                                            unixHost:unixHost,
                                                            osUsername:osUsername,
                                                            loginPasswd:loginPasswd,
                                                            costId:costId
                                                        },
                                                        success: function () {
                                                            window.location.href="/servicelist";
                                                        },
                                                        error:function () {
                                                            alert("同步出错");
                                                        }
                                                    });
                                                }else{
                                                    alert("3");
                                                }
                                            }
                                        });
                                    }
                                });
                            }else{
                                alert("2");
                            }
                        }
                    });
                }else{
                    alert("1");
                }
            },
            error:function (data) {
              alert("");
            }
        });
           /* var unixHost=$("#unixHost").val();
            var loginPasswd=$("#loginPasswd").val();
            var loginPasswd2=$("#loginPasswd2").val();
            //alert(osUsernameisexist(osUsername));
            if (osUsernameisexist(osUsername)){
                alert(loginPasswd==loginPasswd2);
                if (loginPasswd==loginPasswd2){
                    alert(accountId);
                    alert(unixHost);
                    alert(osUsername);
                    alert(loginPasswd);
                    alert(costId);
                    $.ajax({
                        url: "/addservice",
                        type: "post",
                        data:{
                            accountId:accountId,
                            unixHost:unixHost,
                            osUsername:osUsername,
                            loginPasswd:loginPasswd,
                            costId:costId
                        },
                        success: function () {
                            window.location.href="/servicelist";
                        },
                        error:function () {
                            alert("同步出错");
                        }
                    });
                }else {
                    alert("ao");
                }
            }else{
                showResultDiv(true);
                window.setTimeout("showResultDiv(false);", 3000);
            }*/

    }
    function showResultDiv(flag) {
        var divResult = document.getElementById("save_result_info");
        if (flag)
            divResult.style.display = "block";
        else
            divResult.style.display = "none";
    }

    //自动查询账务账号
    function searchAccounts(txtObj) {
        //document.getElementById("a1").innerHTML = txtObj.value;
    }
</script>
</body>
</html>
